package com.alpsoft.spotcheck.adapter;

import java.util.List;
import java.util.Map;

import android.content.Context;
import android.graphics.Color;
import android.view.View;
import android.view.ViewGroup;
import android.widget.SimpleAdapter;

/**
 * 为展示点检任务的listview更改背景颜色的功能，绿色代表点检，黄色代表点检未完成，红色代表异常。
 * 
 * @author Nasir
 * 
 */
public class BackColorListViewAdapter extends SimpleAdapter {

	private List<? extends Map<String, ?>> mData;

	public BackColorListViewAdapter(Context context,
			List<? extends Map<String, ?>> data, int resource, String[] from,
			int[] to) {
		super(context, data, resource, from, to);
		// TODO Auto-generated constructor stub
		mData = data;
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		// TODO Auto-generated method stub
		View v = super.getView(position, convertView, parent);
		Map<String, ?> map = mData.get(position);
		String color = (String) map.get("color");

		if ("transparent".equals(color)) {
			v.setBackgroundColor(Color.TRANSPARENT);
		} else if ("yellow".equals(color)) {
			v.setBackgroundColor(Color.YELLOW);
		} else if ("green".equals(color)) {
			v.setBackgroundColor(Color.GREEN);
		}
		return v;
	}
}
